﻿using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.ComponentModel.Design;
using System.Linq;
using System.Net.NetworkInformation;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using XuanXiang.Infrastructure.Attr;

namespace XuanXiang.Infrastructure.IOC
{
    public static class Inject_help
    {
        public static void AddScoped(this IServiceCollection service,Assembly providers,Assembly Injects) {
            var provider = providers.GetTypes().Where(d => d.GetCustomAttribute(typeof(Provider_Attribute)) != null).ToList();
            var inject = Injects.GetTypes().Where(d => d.GetCustomAttribute(typeof(Inject_Attribute)) != null).ToList();

            provider.ForEach(d => {
                var list = inject.Where(e => d.IsAssignableFrom(e)).ToList();
                list.ForEach(e => {
                    service.AddScoped(d, e);
                });
            });
        }
    }
}
